package com.yfp.operation.controller;

import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.common.log.annotation.Log;
import com.yfp.common.log.enums.BusinessType;
import com.yfp.operation.domain.Client;
import com.yfp.operation.domain.ClientBill;
import com.yfp.operation.domain.dto.ClientBillsDTO;
import com.yfp.operation.domain.dto.StoredBillDTO;
import com.yfp.operation.domain.dto.StoredRefundDTO;
import com.yfp.operation.domain.dto.SurplusFundingDTO;
import com.yfp.operation.domain.vo.StoredBillVO;
import com.yfp.operation.service.ClientService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 用户
 *
 * @CreateDate: 2024/6/13 19:13
 * @UpdateUser:
 * @UpdateDate: 2024/6/13 19:13
 * @UpdateRemark: 暂无修改
 * @Version: 1.0
 */
@RestController
@RequestMapping("/opclient")
@Tag(name = "客户")
public class ClientController extends BaseController {
    @Autowired
    private ClientService clientService;

    @Operation(summary = "客户列表")
    @GetMapping("/list")
    public R<TableDataInfo<List<Client>>> list(Client client) {
        startPage();
        List<Client> list = clientService.findList(client);
        List<Client> list2 = clientService.client2VO(list);
        TableDataInfo dataTable = getDataTable(list2);
        return R.ok(dataTable);
    }


    @Operation(summary = "修改客户")
    @Log(title = "修改客户", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody Client client) {
        clientService.edit(client);
        return R.ok();
    }


    /**
     * 储值记录
     * @param storedBillDTO
     * @return
     */
    @GetMapping("/storedBill")
    @Operation(summary = "储值记录")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StoredBillVO.class)))})
    public TableDataInfo storedBill(StoredBillDTO storedBillDTO){
        startPage();
        List<StoredBillVO> storedBillVOS = clientService.storedBill(storedBillDTO);
        TableDataInfo dataTable = getDataTable(storedBillVOS);
        List<StoredBillVO> storedBillVOList = clientService.storedBillComplement(storedBillVOS);
        dataTable.setRows(storedBillVOList);
        return dataTable;
    }


    /**
     * 储值余额管理
     * @param surplusFundingDTO
     * @return
     */
    @GetMapping("/surplusFunding")
    @Operation(summary = "储值余额管理")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = StoredBillVO.class)))})
    public TableDataInfo surplusFunding(SurplusFundingDTO surplusFundingDTO){
        startPage();
        return getDataTable(clientService.surplusFunding(surplusFundingDTO));
    }


    /**
     * 余额变动明细
     *
     * @param clientBillsDTO
     * @return
     */
    @GetMapping("/clientBills")
    @Operation(summary = "余额变动明细")
    @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "Successful response", content = @Content(mediaType = "application/json", schema = @Schema(implementation = ClientBill.class)))})
    public TableDataInfo clientBills(ClientBillsDTO clientBillsDTO) {
        startPage();
        return getDataTable(clientService.clientBills(clientBillsDTO));
    }


    @PostMapping("/refund")
    @Operation(summary = "储值退款")
    public R<?> refund(@RequestBody StoredRefundDTO storedRefundDTO) {
        return clientService.refund(storedRefundDTO);
    }


    @PostMapping("/updatePositionId")
    @Operation(summary = "修改客户点位标签")
    R<Void> updatePositionId(@RequestParam("orderId") String orderId){
        clientService.updatePositionId(orderId);
        return R.ok();
    }


}